  package edu.hawaii.halealohacli;

  import static org.junit.Assert.assertEquals;
  import static org.junit.Assert.assertFalse;
  import static org.junit.Assert.assertTrue;
  import javax.xml.datatype.XMLGregorianCalendar;
  import org.junit.Test;
  import org.wattdepot.client.WattDepotClient;
  /**
   * Test cases for setBaseline.
   * @author Jordan Do
   *
   */
public class TestSetBaseline {

    // URL to the WattDepot server
    String url = "http://server.wattdepot.org:8190/wattdepot/";
    // Create a WattDepotClient with URL
    WattDepotClient client = new WattDepotClient(url);
    String towerName = "Mokihana";
    String time = "2011-12-10";
    SetBaseline setBaselineDefault = new SetBaseline(towerName, client);
    SetBaseline setBaseline = new SetBaseline(towerName, time, client);
    //we all know world is ending in 2012 so using 2013 for error time
    SetBaseline setBaselineError = new SetBaseline(towerName, "2013-01-01", client);

    /**
     * Checks to see if the values entered in the constructor for energy-since processes right.
     */
    @Test
    public void testValues() {
      assertEquals("Test to see if tower names match for default", towerName, 
          setBaselineDefault.getTower());
      assertEquals("Test to see if tower names match", towerName, setBaseline.getTower());
    }

    /**
     * Test the run method of base-line to confirm that bad dates are handled.
     */
    @Test
    public void testRun() {
      try {
        assertTrue("Test run with good default values", setBaselineDefault.run());
        assertTrue("test run with good values", setBaseline.run());
        assertFalse("Test run with bad values", setBaselineError.run());
      }
      catch (Exception e) {
        System.out.println("Error occured when running testRun.");
      }
    }
    
    /**
     * Test the trueRun method to confirm that a double[] size 24 is being returned.
     */
    @Test
    public void testTrueRun() {
      try {
        assertEquals("Array should be 24 (default)", 24, setBaselineDefault.trueRun().length);
        assertEquals("Array should be 24 (entered date)", 24, setBaseline.trueRun().length);
      }
      catch (Exception e) {
        System.out.println("Error occured when running testTrueRun");
      }
    }
    
    /**
     * Tests to make sure days are handled correctly.
     */
    @Test
    public void testSetStartDay() {
      boolean value = false;
      try {
        XMLGregorianCalendar testDefault = setBaselineDefault.setStartDay();
        XMLGregorianCalendar test = setBaseline.setStartDay();
        if (test.getHour() == 0 &&
            test.getMinute() == 0 &&
            test.getSecond() == 0 &&
            testDefault.getHour() == 0 &&
            testDefault.getMinute() == 0 &&
            testDefault.getSecond() == 0) {
          value = true;
        }
        assertTrue("Default and user chosen go to start of day", value);
      }
      catch (Exception e) {
        System.out.println("Error occured when running testSetStartDay");
      }
    }
  }